package com.jyx.spring.action;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.jyx.spring.action.service.IPerformer;
import com.jyx.spring.action.service.impl.PerformerOfHank;
import com.jyx.spring.action.service.impl.PerformerOfKenny;

import sun.misc.GC;

public class Test {

	public static void main(String[] args) {
		
		ApplicationContext context = new ClassPathXmlApplicationContext("com/jyx/application.xml");
		/* 简单bean：构造注入 */
		// 表演者：会表演
//		IPerformer perfor = (IPerformer) context.getBean("duke");
//		perfor.perform();
		/* 简单bean：构造注入引用 */
		// 表演者：会表演，会吟唱
//		IPerformer dukeOne = (IPerformer) context.getBean("dukeOne");
//		dukeOne.perform();
		/* 单例模式：scope="singleton" */
		// 舞台：唯一一个
//		Stage stage1 = (Stage) context.getBean("stage");
//		Stage stage2 = (Stage) context.getBean("stage");
//		Stage stage3 = (Stage) context.getBean("stage");
//		Stage stage4 = (Stage) context.getBean("stage");
//		System.out.println("stage1:"+stage1+",stage2:"+stage2+",stage3:"+stage3+",stage4:"+stage4);
//		System.out.println((stage1 == stage2) + "-" + (stage2 == stage3) +"-" + (stage3 == stage4));
		/* 多例模式：scope="prototype" */
		// 门票：人手一张，且门票号码不一样
//		Ticket ticket1 = (Ticket) context.getBean("ticket");
//		Ticket ticket2 = (Ticket) context.getBean("ticket");
//		Ticket ticket3 = (Ticket) context.getBean("ticket");
//		Ticket ticket4 = (Ticket) context.getBean("ticket");
//		System.out.println("ticket1:"+ticket1+",ticket2:"+ticket2+",ticket3:"+ticket3+",ticket4:"+ticket4);
//		System.out.println((ticket1 == ticket2) + "-" + (ticket2 == ticket3) +"-" + (ticket3 == ticket4));
		/* bean实例化和销毁的时候执行操作  */
		// 实例化bean的初始化和销毁方法：init-method\destroy-method="methodName"
//		Auditorium auditorium = (Auditorium) context.getBean("auditorium");
		
		// kenny 是一个参赛者(poem),可以唱歌,可以演奏任何乐器
		PerformerOfKenny instrumenta = (PerformerOfKenny) context.getBean("kenny");
		instrumenta.perform();
		
		/* 集合数据组装：list,set,map,props */
		// list:hank是一个多才的演奏者，可以同时演奏多种乐器，号称一个人的乐队
		PerformerOfHank hank = (PerformerOfHank) context.getBean("hank");
		hank.perform();
		// 当hank拥有的乐器需要指定每一个的名称的时候，list就不能完成该功能了，需要Map集合了
		
	}

}
